package kr.hkit.powerjava.chther24.work;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;

public class TestMain {
	public static void main(String[] args) {
		StudentDao dao = new StudentDao();
//		Student std = new Student(1, "김태희", 90, 80, 70);
//		dao.insertItem(new Student(1, "김태희", 90, 80, 70));
//		dao.insertItem(new Student(2, "김태우", 100, 100, 100));
//		dao.insertItem(new Student(3, "이민정", 90, 80, 50));
//		dao.saveList();
	
		dao.loadList();
//		dao.insertItem(new Student(4, "이민장", 90, 80, 50));
//		dao.saveList();
		dao.prnItem();
	
		
//		dao.insertItem(new Student(1, "김태희", 90, 80, 70));
//		dao.insertItem(new Student(2, "김태우", 100, 100, 100));
//		
//		dao.prnItem();
//		
//		dao.saveList();
		
//		dao.loadList();
//		dao.prnItem();
//		
//		dao.insertItem(new Student(3, "이민정", 90, 80, 50));
//		dao.saveList();
		
		/*ArrayList<Student> arlist = new ArrayList<>();

		Student std = new Student(1, "김태희", 90, 80, 70);
		// System.out.println(std);
		Student std2 = new Student(2, "김태우", 100, 100, 100);
		// System.out.println(std2);
		arlist.add(std);
		arlist.add(std2);
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		BufferedInputStream bis = null;
		PrintWriter pw = null;

		try {
			oos = new ObjectOutputStream(new FileOutputStream(
					"StuedntList.dat"));
			oos.writeObject(arlist);
			for (Student temp : arlist) {
				oos.writeObject(temp);
			}
			// oos.writeObject(std);
			// oos.writeObject(std2);
			// oos.writeObject(arlist);
			oos.flush();

			ois = new ObjectInputStream(new FileInputStream("StuedntList.dat"));
			ArrayList<Student> list = new ArrayList<>();
			list = (ArrayList<Student>)ois.readObject();
//			while (ois.available() != -1) {
//				try {
//					list.add((Student) ois.readObject());
//					// Student std3 = (Student) ois.readObject();
//					// System.out.println(std3);
//				} catch (EOFException e) {
//					break;
//				}
//			}
			for (Student st : list) {
				System.out.println(st);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (oos != null)
				try {
					oos.close();
				} catch (Exception e2) {
					// TODO: handle exception
				}
			if (ois != null)
				try {
					ois.close();
				} catch (Exception e2) {
					// TODO: handle exception
				}

		}*/

	}
}
